home *** CD-ROM | disk | FTP | other *** search
-
- GRAND TOUR OF JFORTH
-
- The section describes some of the special features of
- JForth. If you have never used any Forth, you may want to
- try the tutorial first.
-
- Let's start with a grand tour of the main JForth tools.
- Bring up the JForth demo and try out these commands as we
- discuss them. (If you are unclear about how to read stack
- diagrams, please try the tutorial first.)
-
- WORDS-LIKE ( <word-fragment> -- , list all with fragment )
-
- Use this if you want to see all of the words that have some
- word fragment in their name. ENTER:
-
- WORDS-LIKE EMIT ( all words with EMIT )
- WORDS-LIKE + ( all words with '+' )
-
- As a shortcut, if you hit <Function-Key-6> it will insert
- WORDS-LIKE into your input stream. This will save you from
- having to type it in. Hit the <HELP> key to find out about
- other function key assignments. Now hit the <Up-Arrow> key
- repeatedly to scroll through your previous commands just
- like in the Amiga DOS shell. You can look in the section on
- Command Line History for more information about this.
-
- WORDS ( -- , list the words currently available )
-
- This command lists the words in the dictionary that you can
- call. Although thousands of words may be listed, you will
- only need to learn a few. You can stop the output of this
- list by hitting a key. Hit return to continue listing or
- enter "quit" to stop. You could also enter a Forth command
- while WORDS is paused. This pause feature is provided by
- ?PAUSE which is described in the glossary. VLIST is a
- synonym for WORDS.
-
- DEF ( <name> -- , disassemble word )
-
- Here is a handy word for those of you who are familiar with
- 68000 assembly language. DEF will disassemble any Forth
- word. ENTER:
-
- DEF 1+
- DEF CMOVE
-
- In the release version of JForth, the first time you enter
- DEF it will load a precompiled MODULE containing the
- disassembler. This gives you quick access to DEF without
- taking up room in the dictionary or having to compile it
- yourself.
-
- DOS ( <command-line> -- , pass command to Amiga DOS )
-
- You can execute almost any Amiga DOS command line except
- those that require input, and CD. For CD, just enter CD
- without using the DOS keyword (CD has been provided for you
- in the JForth dictionary). Some common DOS commands have
- been predefined.
-
- Let's execute a DOS command. ENTER:
-
- DOS TYPE S:STARTUP-SEQUENCE OPT H
-
- For CD, use CD directly.
-
- CD RAM:
-
- Use predefined command.
-
- DIR DF0:
-
- Pass command in string.
-
- " RENAME RAM:MOO RAM:GOO" $DOS
-
- MEASURE ( <Forth-line> -- , time Forth commands )
-
- This is handy when you are trying to speed up your code.
- This command will tell you how long things take. It will
- take the commands that follow, execute them and tell you how
- long it took.
-
- MEASURE DIR
-
- BENCH ( <Forth-line> -- , time commands with overhead )
-
- MEASURE and BENCH are only accurate to about 1/50th of a
- second. If something takes less than 1/2 a second you
- should call it N times in a loop then divide by N to find
- out the actual time. If you want to take the loop overhead
- into account, use BENCH and BENCH.WITH.
-
- : TDO ( N -- )
- 0 DO LOOP
- ;
- : TSWAP ( a b count -- a b | b a )
- 0 DO SWAP LOOP
- ;
- 1,000,000 BENCH.WITH TDO
- 11 22 33 1,000,000 BENCH TSWAP
-
- INCLUDE ( <filename> -- , compile source code from a file)
-
- You can specify a complete pathname or use the current
- directory. INCLUDE can be nested so you can call INCLUDE in
- the file you are currently INCLUDEing. (See INCLUDE? in the
- glossary.) INCLUDE is a very important word so we have
- assigned it to <Function-Key-1>.
-
- INCLUDE JU:RANDOM
- 6 CHOOSE . ( random number, 0 <= R < 5 )
- 6 CHOOSE .
-
- TYPEFILE JU:LOGTO
- MEASURE INCLUDE JU:LOGTO
-
- JForth uses a HASHED dictionary to speed up compilation.
- This is a special way of looking words up directly instead
- of scanning the entire dictionary. If we turn off hashing we
- can see how hashing speeds up the compile process...
-
- HASH.OFF
- MEASURE INCLUDE JU:LOGTO
-
- Notice how compilation is slower without hashing. Hashing
- does not, however, come without a price. JForth has to
- build a table of pointers for hashing to work. This
- rehashing is required whenever you FORGET code or do a
- GETMODULEs. If we recompile LOGTO with hashing on we will
- have to rehash.
-
- HASH.ON
- MEASURE INCLUDE JU:LOGTO
-
- This is still faster than compiling with hashing off.
- Hashing is most effective with large files when the
- dictionary has lots of words already defined. Some people
- have reported an 8-9 times speed up. Hashing is least
- effective when you recompile small files but they are pretty
- fast anyway. Hashing will speed up compilation in almost
- every instance so we usually leave it on.
-
- MAP ( -- , display system status )
-
- This word tells you all about the current system, how many
- files are open, how much room is left in the dictionary,
- etc. This is assigned to a function key. Hit <HELP> to
- find out which one.
-
- FILE? ( <name> -- , show file and source code )
-
- If you are curious about how a word is defined you can use
- FILE? to see what file it is from. It will then ask you if
- you want to see everywhere it is referenced or defined in
- that file. [Note: The demo version will not show you the
- source code to the pre-compiled JForth words, because the
- source files are not included. In the normal release,
- almost all of the source IS provided.]
-
- FILE? ANEW
-
- EACH.FILE? ( <name> -- , show every file and source code )
-
- If a word has been redefined, this command will find every
- occurrence of it in the dictionary and show it to you.
-
- EACH.FILE? AUTO.INIT
- EACH.FILE? [FORGET]
-
- SAVE-FORTH ( <filename> -- , save current JForth system )
-
- SAVE-FORTH is disabled in the Demo Version. SAVE-FORTH
- allows you to save a new dictionary with many files loaded
- in. Thus you could save a dictionary withh all of the ANIM
- code precompiled. This can save considerable time when
- working on large projects. SAVE-FORTH also allows you to
- expand the dictionary as it saves. This is disabled in the
- demo version so that you can not expand the available
- dictionary.
-